#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# Project: spd-sxmcc
"""
@author: lyndon
@time Created on 2019/1/3 13:22
@desc 闭包 定义：嵌套函数，内部函数调用外部函数的变量
"""
# a = 1 全局的变量在这里，也不叫闭包

# def outer():
#     a = 1
#
#     def inner():
#         print(a)
#
#     print(inner.__closure__)   # (<cell at 0x0067C030: int object at 0x00658690>,) 打印closure，如果是cell就是闭包
#     return inner
#
#
# inn = outer()
# print(outer.__closure__)   # None ,说明outer不是闭包，inner才是闭包
#
# inn()


from urllib import urlopen
# ret = urlopen('http://www.xiaohua100.cn/index.html').read()
# print(ret)

def get_url():
    url = 'http://www.xiaohua100.cn/index.html'
    def inner():
        ret = urlopen(url).read()
        print(ret)
    return inner

get_func = get_url()

get_func()

